package com.wbc.smartHome.web;

import com.wbc.smartHome.model.Result;
import com.wbc.smartHome.model.SystemInfo;
import com.wbc.smartHome.service.SystemInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.IOException;


@RestController
@RequestMapping(path = "/api/SystemInfoCtl")
public class SystemInfoController {


    @Autowired
    private SystemInfoService systemInfoService;



    @RequestMapping(path = "/SystemInfo")
    public Result getSystemInfo(){
        SystemInfo systemInfo = systemInfoService.systemInfoList();
        Result result  = new Result(200,"查询成功",systemInfo);
        return result;
    }

    @RequestMapping(path = "/save")
    public Result save(@RequestBody SystemInfo systemInfo,@RequestHeader("adminToken") String adminToken){
        systemInfoService.updateSystemInfo(systemInfo,adminToken);
        Result result = new Result(200, "保存成功", null);
        return  result;
    }

    /*上传新闻封面图*/
    @PostMapping("/uploadImg")
    public Result uploadImg(@RequestParam("file")CommonsMultipartFile commonsMultipartFile) throws IOException {
        Result result = systemInfoService.uploadImg(commonsMultipartFile);
        return  result;
    }

    @GetMapping(path = "deleteImg")
    public Result deleteImg(String imgurl) throws IOException {
        systemInfoService.deleteImg(imgurl);
        return new Result(200,"删除成功",null);
    }
}
